####################################################-*- coding: utf-8 -*-#####
#
#
# utils module, provide various thread safe useful methods, 
# TODO: provide more power print like print(*arg1, **arg2)
# 
#
##############################################################################
import os
import sys
import configparser
from datetime import datetime
from threading import Lock

iolock = Lock()

def error(msg):
    """ A thread safe error function
        After show the error message, inform the main thread to pause
        all activity if we require it to do so.
    """
    with iolock:
        print('ERROR: %s'%msg)
        # TODO, inform main thread that error occurs


def warning(msg):
    """ A thread safe warning function
        After show the error message, inform the main thread to pause
        all activity if we require it to do so.
    """
    with iolock:
        print('WARNING: %s'%msg)
        # TODO, inform main thread that warning occurs

def info(msg):
    with iolock:
        print('INFO: %s'%msg)
        
# Return the root dir of this tool
def getRootDir():
    fullpath = os.getcwd() + os.sep + sys.argv[0]
    return os.path.dirname(fullpath)

def getConfigFile():
    rootpath = getRootDir()
    cfg_file = rootpath + os.sep + CFG_FILE
    if os.path.exists(cfg_file) is False:
        error('File "%s" is missing'%CFG_FILE)
        exit()

    return cfg_file
    

